package cn.consult.controller.sys.park;

import cn.consult.common.api.CommonResult;
import cn.consult.sys.entity.TPlaceFloor;
import cn.consult.sys.entity.TPlaceRoom;
import cn.consult.sys.service.TPlaceRoomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "园区管理 > 场地房间")
@RequestMapping("/park/room")
public class TPlaceRoomController {

    @Autowired
    TPlaceRoomService tPlaceRoomService;

    @ApiOperation("getRoomByFloorId =>  根据楼层id查询房间集合")
    @GetMapping("/getRoomByFloorId/{roomId}")
    public CommonResult getRoomByFloorId(@PathVariable Long roomId) {
        List<TPlaceRoom> list = tPlaceRoomService.getRoomByFloorId(roomId);
        return CommonResult.success(list);
    }

    @ApiOperation("addRoom =>  添加房间")
    @PostMapping("/addRoom")
    public CommonResult addRoom(@RequestBody TPlaceRoom tPlaceRoom) {
        tPlaceRoom.setCreateTime(new Date().toString());
        return CommonResult.success(tPlaceRoomService.save(tPlaceRoom));
    }
    @ApiOperation("updateRoom =>  修改房间")
    @PutMapping("/updateRoom")
    public CommonResult updateRoom(@RequestBody TPlaceRoom tPlaceRoom) {
        tPlaceRoom.setCreateTime(new Date().toString());
        return CommonResult.success(tPlaceRoomService.updateById(tPlaceRoom));
    }
    @ApiOperation("getRoomById =>  根据id查询房间信息")
    @GetMapping("/getRoomById/{id}")
    public CommonResult getRoomById(@PathVariable Long id) {
        TPlaceRoom byId = tPlaceRoomService.getById(id);
        return CommonResult.success(byId);
    }

    @ApiOperation("getRoomAll =>  条件查询房间")
    @GetMapping("/getRoomAll")
    public CommonResult getRoomAll(@RequestParam Map<String, Object> params) {
        List<TPlaceRoom> rooms = tPlaceRoomService.selectByRoomNameOrNumber(params);
        return CommonResult.success(rooms);
    }
    @ApiOperation("deleteRoomByid =>  删除房间")
    @DeleteMapping("/deleteRoomByid/{id}")
    public CommonResult deleteRoomByid(@PathVariable Long id) {
        return CommonResult.success(tPlaceRoomService.removeById(id));
    }
}
